package bean.resource;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;

import dao.resource.*;
import dao.task.*;
import entity.task.Task;
import entity.resource.*;
import bean.resource.*;
import entity.user.*;

@Named
@RequestScoped
public class ResourcesListBean {

	private Long taskId;
	private Task task;
	private Long resourceId;
	private List<Resource> resources = new ArrayList<Resource>();

	@Inject
	private ResourceDAO resourceDao;

	@Inject
	private TaskDAO taskDao;

	@Inject
	private ResourceBean resBean;

	public String searchAction() {

		resources = resourceDao.findByTaskId(taskId);

		return "";
	}

	public String searchFreeResource() {

		resources = resourceDao.findFreeResources();

		return "";
	}

	public String searchActionByTask() {

		resources = resourceDao.findByTaskId(taskId);

		return "";
	}

	@SuppressWarnings("unused")
	public String save() {
		if (resourceId > 0) {
			Task task;
			task = taskDao.findById(taskId, false);
			// res.setTask(task);
			Resource res;
			resources.clear();
			res = resourceDao.findById(resourceId, false);
			resBean.setResource(res);
			resBean.save();
		}
		return "";

	}

	public Long getTaskId() {
		return taskId;
	}

	public void setTaskId(Long taskId) {
		this.taskId = taskId;
	}

	public Long getResourceId() {
		return resourceId;
	}

	public void setResourceId(Long resourceId) {
		this.resourceId = resourceId;
	}

	public List<Resource> getResources() {
		return resources;
	}

	public void setResources(List<Resource> resources) {
		this.resources = resources;
	}

	public ResourceDAO getResourcekDao() {
		return resourceDao;
	}

	public void setResourceDao(ResourceDAO resourceDao) {
		this.resourceDao = resourceDao;
	}

	public Task getTask() {
		return task;
	}

	public void setTask(Task task) {
		this.task = task;
	}

}
